package cn.com.niit.controller;

import cn.com.niit.pojo.Menu;
import cn.com.niit.pojo.Merchant;
import cn.com.niit.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class MenuController {
    @Autowired
    MenuService menuService;
    @RequestMapping("/showAllMenu")
    public List<Menu> showAllMenu(String userName){
        return menuService.findAllMenuByMerchantName(userName);
    }
    @RequestMapping("/searchMenu")
    public List<Menu> searchMenu(Menu menu,String p){
        if (p!=null &&!p.equals("")) menu.setPrice(Double.parseDouble(p));
        return menuService.search(menu);
    }
    @RequestMapping("/del")
    public void del(String id){
        menuService.del(Integer.parseInt(id));
    }
    @RequestMapping("/findOne")
    public Menu findOne(String id){
        return menuService.findOne(Integer.parseInt(id));
    }
    @RequestMapping("/revise")
    public void revise(Menu menu){
        menuService.revise(menu);
    }

}
